Table Logic

Saving data, triggering functions, and callbacks for level-specific scripts.

Functions

AddCallback(point, func) Register a function as a callback.
RemoveCallback(point, func) Deregister a function as a callback.
HandleEvent(name, type, [activator]) Attempt to find an event set and execute a particular event from it.
EnableEvent(name, type) Attempt to find an event set and enable specified event in it.
DisableEvent(name, type) Attempt to find an event set and disable specified event in it.


Functions

AddCallback(point, func)
Register a function as a callback.

This is intended for module/library developers who want their modules to do stuff during level start/load/end/save/control phase, but don't want the level designer to add calls to OnStart, OnLoad, etc. in their level script. Any returned value will be discarded.

Note: the order in which two functions with the same CallbackPoint are called is undefined.

i.e. if you register MyFunc and MyFunc2 with PRE_LOOP, both will be called in the beginning of game loop, but there is no guarantee that MyFunc will be called before MyFunc2, or vice-versa.

Arguments:

  • The callbacks PRE_END, POST_END, PRE_USE_ITEM, and POST_USE_ITEM receive an argument (like their respective LevelFuncs.OnEnd and LevelFuncs.OnUseItem).

  • The argument for PRE_LOOP and POST_LOOP is deprecated and should not be used.

Parameters:

  • point CallbackPoint When should the callback be called?
  • func function The function to be called (must be in the LevelFuncs hierarchy). Will receive, as an argument, the time in seconds since the last frame.

Usage:

    LevelFuncs.MyFunc = function()
    	-- do stuff here
    end
    TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRE_START, LevelFuncs.MyFunc)
    
    -- Another example, with argument
    LevelFuncs.OnLevelEnd = function(reason)
    	-- do stuff here
    	print("Level ended because reason code: " .. reason)
    end
    TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.PRE_END, LevelFuncs.OnLevelEnd)
    
    -- Another example, two functions added in the same callback type
    LevelFuncs.FuncA = function()
    	-- do stuff here
    end
    LevelFuncs.FuncB = function()
    	-- do other stuff here
    end
    TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.POST_LOAD, LevelFuncs.FuncA)
    TEN.Logic.AddCallback(TEN.Logic.CallbackPoint.POST_LOAD, LevelFuncs.FuncB)
    -- In this case, both FuncA and FuncB will be called after level load, but the order is undefined.
RemoveCallback(point, func)
Deregister a function as a callback. Will have no effect if the function was not registered as a callback

Parameters:

Usage:

    TEN.Logic.RemoveCallback(TEN.Logic.CallbackPoint.PRELOOP, LevelFuncs.MyFunc)
HandleEvent(name, type, [activator])
Attempt to find an event set and execute a particular event from it.

Parameters:

  • name string Name of the event set to find.
  • type EventType Event to execute.
  • activator Moveable Optional activator. Default: Lara.

Usage:

    -- Executes the "ENTER" volume event of the event set named "MyVolumeEvent"
    TEN.Logic.HandleEvent("MyVolumeEvent", TEN.Logic.EventType.ENTER)
    
    -- Executes the "LOAD" global event of the event set named "MyGlobalEvent", with enemy as activator
    enemy = TEN.Objects.GetMoveableByName("MyEnemy")
    TEN.Logic.HandleEvent("MyGlobalEvent", TEN.Logic.EventType.LOAD, enemy)
EnableEvent(name, type)
Attempt to find an event set and enable specified event in it.

Parameters:

  • name string Name of the event set to find.
  • type EventType Event to enable.

Usage:

    -- Enables the "ENTER" volume event of the event set named "MyVolumeEvent"
    TEN.Logic.EnableEvent("MyVolumeEvent", TEN.Logic.EventType.ENTER)
DisableEvent(name, type)
Attempt to find an event set and disable specified event in it.

Parameters:

  • name string Name of the event set to find.
  • type EventType Event to disable.

Usage:

    -- Disables the "ENTER" volume event of the event set named "MyVolumeEvent"
    TEN.Logic.DisableEvent("MyVolumeEvent", TEN.Logic.EventType.ENTER)
generated by TEN-LDoc (a fork of LDoc 1.4.6)